<template>
    <div style="width: 86%;margin: 0 auto;margin-top: 50px;">
        <el-button :style='{"border":"0","cursor":"pointer","padding":"0 10px","margin":"0 5px 0 0","outline":"none","color":"#333","borderRadius":"0px","background":"#1abc9e30","width":"auto","lineHeight":"36px","fontSize":"14px","height":"36px"}' type="warning" size="mini" @click="backClick" class="el-icon-back">返回</el-button>
        <el-table :data="tableData" style="width: 100%" height="600" :loading="loading">
            <el-table-column type="index" label="序号" width="80"/>
            <el-table-column prop="content" label="消息内容" />
            <el-table-column prop="addtime" label="创建时间" />
        </el-table>
        <div class="paginationBox">
            <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
                :current-page="paginationObj.page" :page-sizes="[10, 20, 30, 40]" :page-size="100"
                layout="total, sizes, prev, pager, next, jumper" :total="total">
            </el-pagination>
        </div>
    </div>
</template>
<script>
export default {
    data() {
        return {
            tableData: [],
            paginationObj: {
                page: 1,
                limit: 10
            },
            total: 0,
            loading: false
        }
    },
    created() {
        this.getListData()
    },
    methods: {
        getListData() {
            this.loading = true
            this.$http.get('message/page', {params: { ...this.paginationObj }}).then(res => {
				if (res.data.code == 0) {
					this.tableData = res.data.data.list;
                    this.total = res.data.data.total;
				}
			}).finally(() => {
                this.loading = false
            });
        },
        handleSizeChange(val) {
            this.paginationObj.limit = val;
            this.getListData()
            console.log(`每页 ${val} 条`);
        },
        handleCurrentChange(val) {
            this.paginationObj.page = val;
            this.getListData()
            console.log(`当前页: ${val}`);
        },
        backClick() {
          this.$router.push('/index/center')
      },
    },
}
</script>
<style scoped>
.paginationBox {
    padding: 50px 0;
}
</style>